<?php
/*
 * This file is part of the BooXtore Student project.
 *
 * (c) Francis Backeland f.backeland@gmail.com
 * (c) Laurine Chaplot chaplot.laurine@orange.fr
 * (c) Julien Dutot julien.dutot@gmail.com
 * (c) Romain Guillaume romain-guillaume@orange.fr
 * (c) Guillaume Paringaux g.paringaux@gmail.com
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code
 */

namespace BXTR\AdminBundle\Controller;

/**
 * User managment
 */
class UserController extends EntityController
{
    /**
     * Encode the user password from the fake_password field.
     *
     * @param mixed $entity
     * @param mixed $form
     * @param mixed $addition
     */
    public function doPersist($entity, $form, $addition=false)
    {
        $password = $form->get('fake_password')->getData();
        if ($form->get('fake_password')->getData() != null) {
            $factory = $this->get('security.encoder_factory');
            $encoder = $factory->getEncoder($entity);

            $entity->setpassword($encoder->encodepassword($password, $entity->getsalt()));
        }
        if ($addition) {
            $entity->setdatesubscribe(new \datetime());
        }
        parent::doPersist($entity, $form);
    }
};
